package com.wust.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {
	
	public static String converTime(String  strtime){
	
			
			Date date;
			DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
			try {
				date=format1.parse(strtime);
			} catch (ParseException e) {
				return strtime;
			}
			long publishtime=date.getTime()/1000;
			long nowtime=new Date().getTime()/1000;
			long subtime = (nowtime - publishtime) / 60;
		    long longhousetime = subtime / 60;
		    long dayhousetime = longhousetime / 24;
		
		    if(dayhousetime==0)
		    	return "今天";
		    else if(dayhousetime==1)
		    	return "昨天";
		    else if(dayhousetime==2)
		    	return "前天";
		    else return dayhousetime+"天前";
		}
	
	
	public static String getStandardTime(long timestamp){
		SimpleDateFormat sdf;
		Date date;
		if(timestamp!=0)
		{
			date = new Date(timestamp*1000);
			sdf = new SimpleDateFormat("MM月dd日 HH:mm");
		}else 
		{
			date=new Date();
			sdf=new SimpleDateFormat("yy-MM-dd HH:mm:ss");
		}
		sdf.format(date);
		return sdf.format(date);
	}
}
